
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Correo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author estudiante
 */
public abstract class Conexion extends Mail {

    public static String dominio = null;
    public static String user = null;
    public static String pass = null;
    public PrintWriter out = null;
    public BufferedReader in = null;
    public Socket socket = null;
    public int puerto = 0;

    public abstract boolean conectar();

    public String enviarMensaje(String mensaje) throws IOException {
        if (mensaje != null) {
            this.out.println(mensaje);
            this.out.flush();
        }
        return leer();
    }

    public String leer() throws IOException {
        return in.readLine();
    }

    public void deconectar() {
        try {
            enviarMensaje("QUIT");
            socket.close();
            out.close();
            in.close();
            System.out.println("cerrando puerto POP110 exit ok");
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Error:No se pudo cerrar la conexion");
            System.out.println();
        }
    }
}
